//
//  xwzx.m
//  上海杨浦
//
//  Created by FrankChen on 13-12-13.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "xwzx.h"
#import "ServiceHelper.h"

@implementation xwzx

@synthesize linkArray;
@synthesize titleArray;
@synthesize content;


-(void)getTile:(NSString *) lanmu :(NSInteger)pageIndex{
    
    
    NSMutableArray *params=[NSMutableArray array];
    //[params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"0093000200030001",@"ModuleId", nil]];
    //[params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"20",@"PageSize", nil]];
    //[params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"CurrentPageIndex", nil]];
    NSString *page=[NSString stringWithFormat:@"%d",pageIndex];
    
//    [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:lanmu,@"name", nil]];
    [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"20",@"PageSize", nil]];
    [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:page,@"CurrentPageIndex", nil]];
    
    
    {
        [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"OuCode", nil]];
        [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"009300020005",@"ModuleId", nil]];
        [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"DateFrom", nil]];
        [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"DateTo", nil]];
//        <OuCode>string</OuCode>
//        <ModuleId>string</ModuleId>
//        <DateFrom>string</DateFrom>
//        <DateTo>string</DateTo>
//        <PageSize>string</PageSize>
//        <CurrentPageIndex>string</CurrentPageIndex>
    }
    
    
    ServiceArgs *args1=[[[ServiceArgs alloc] init] autorelease];
//    args1.serviceURL=@"http://www.shyp.gov.cn/WebServices/NewsInfoForApp.asmx";
    args1.serviceURL=@"http://116.228.162.163:8080/xxgk/Webservice/InfoQuery.asmx";
    
    args1.serviceNameSpace=@"http://tempuri.org/";
    args1.methodName=@"GetInfoList";
    args1.soapParams=params;
    
    //NSLog(@"soap=%@\n",args1.soapMessage);
    ServiceResult *result=[ServiceHelper syncService:args1];
    
    //NSLog(@"%@",[result.request responseString]);
    
    NSString *xml=[[result.request responseString] stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    xml=[xml stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    
    //NSLog(@"xml=%@\n",xml);
    NSMutableArray *_linkArray=[[NSMutableArray alloc]init];
    NSMutableArray *_titleArray=[[NSMutableArray alloc]init];
    NSString *tag1=@"<Title>";
    NSString *tag2=@"</Title>";
    NSString *tag3=@"<Infoid>";
    NSString *tag4=@"</Infoid>";
    NSString *title=@"";
    NSString *time=@"";
    NSString *link=@"";
//    NSString *tag5=@"<Time>";
//    NSString *tag6=@"</Time>";
    
    NSString *tag5=@"<InfoDate>";
    NSString *tag6=@"</InfoDate>";
    
    BOOL over=false;
    for (int i=0; i<20; i++) {
        NSRange range1=[xml rangeOfString:tag1];
        
        if (range1.length==0) {
            over=true;
        }
        
        if (!over) {
            
            xml=[xml substringFromIndex:(range1.location+range1.length)];
            
            NSRange range2=[xml rangeOfString:tag2];
            title=[xml substringToIndex:range2.location];
            
            NSRange range3=[xml rangeOfString:tag3];
            xml=[xml substringFromIndex:(range3.location+range3.length)];
            
            NSRange range4=[xml rangeOfString:tag4];
            link=[xml substringToIndex:range4.location];
            
            NSRange range5=[xml rangeOfString:tag5];
            xml=[xml substringFromIndex:(range5.location+range5.length)];
            NSRange range6=[xml rangeOfString:tag6];
            time=[xml substringToIndex:range6.location];
            NSRange range7=[time rangeOfString:@" "];
            time=[time substringToIndex:range7.location];
            
            title=[title stringByAppendingString:@" "];
            title=[title stringByAppendingString:time];
            //title=[title stringByAppendingString:@" 2012-10-10"];
            
            [_titleArray addObject:title];
            

            
            [_linkArray addObject:link];
        }
        
    }
    linkArray=_linkArray;
    titleArray=_titleArray;
}

-(void)getData:(NSString *)infoID{
    
    NSMutableArray *params=[NSMutableArray array];
    
    
    [params addObject:[NSDictionary dictionaryWithObjectsAndKeys:infoID,@"InfoID", nil]];
    
    
    ServiceArgs *args1=[[[ServiceArgs alloc] init] autorelease];
    args1.serviceURL=@"http://www.shyp.gov.cn/WebServices/NewsInfoForApp.asmx";
    args1.serviceNameSpace=@"http://tempuri.org/";
    args1.methodName=@"GetInfoDetail";
    args1.soapParams=params;
    
    //NSLog(@"soap=%@\n",args1.soapMessage);
    ServiceResult *result=[ServiceHelper syncService:args1];
    
    NSString *xml=[[result.request responseString] stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    xml=[xml stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    
    //NSLog(@"xml=%@\n",xml);
    NSString *tag1=@"<Content>";
    NSString *tag2=@"</Content>";
    
    NSRange range1=[xml rangeOfString:tag1];
    if (range1.length!=0) {
        xml=[xml substringFromIndex:(range1.location+range1.length)];
        
        NSRange range2=[xml rangeOfString:tag2];
        xml=[xml substringToIndex:range2.location];
    }
    //xml=[xml stringByReplacingOccurrencesOfString:@"&amp;lt;p&amp;gt;" withString:@""];
    
    xml=[xml stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"&amp;lt;p&amp;gt;\t" withString:@"\r\n"];
    xml=[xml stringByReplacingOccurrencesOfString:@"&amp;lt;/p&amp;gt;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"&amp;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"lt;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"br;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"/&amp;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"amp;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"nbsp;" withString:@""];
    xml=[xml stringByReplacingOccurrencesOfString:@"br /gt;" withString:@""];
    content= xml;
}





@end
